import { resolve } from "path";
import { onBeforeMount, ref } from "vue";
import { globalService } from "~/service/global";

export default function () {
	// 是否开放账号登录
	const accountLoginAuth = +import.meta.env.VITE_APP_ACCOUNT_LOGIN;

	// 默认配置项
	const authConfigs = ref([
		{
			configType: "BACK_LOGIN",
			configStatus: accountLoginAuth,
		},
	]);

	// 获取配置
	const getSettings = async () => {
		try {
			let { ok, data } = await globalService.getAuth<ServiceStructure>(null, {
				query: {
					sysType: "LAND",
				},
			});
			if (ok) {
				authConfigs.value = data.map((item) => {
					item.configStatus = +item.configStatus;
					return item
				})
			}
		} catch {
		}
	};

	// 匹配
	const getTypeAuth = (type: string) => {
		// 根据按钮type返回对应配置
		if (type) {
			const arr = authConfigs.value.filter((item) => item.configType === type);
			return arr[0] && arr[0]?.hasOwnProperty("configStatus")
				? +arr[0].configStatus
				: null;
		}
	}

	onBeforeMount(() => {
		getSettings();
	});

	return {
		authConfigs,
		getTypeAuth,
	};
}
